<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/** // very important annotations
* @property CI_Loader $load
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Email $email
* @property CI_DB_active_record $db
* @property CI_Session $session
* @property CI_Config $config
* @property CI_URI $uri
* @property CI_Upload $upload
* @property CI_Pagination $pagination
* @property CI_Table $table
*
*/

class  WebSearchEngine_model extends CI_Model
{


    
      /** this method search the tags in bing.com ..
     *
     *
     xpages@live.com
     mykfupm111
     AppID for search engine : E6FF55E71CD243D4C518730C491DEB1837CC0FD2
     */

    
     function searchTheWebEngine($keyword)
     {
        //$keyword="summer";
         //echo $keyword;
         $keyword=str_replace(',',' ', $keyword,  sizeof($keyword));
         //echo $keyword;
         $auth = base64_encode('itc\oheron:roinujj');

                $aContext = array(
                    'http' => array(
                        'proxy' => 'proxy.kfupm.edu.sa:80',
                        'request_fulluri' => true,
                        'header' => "Proxy-Authorization: Basic $auth",
                    ),
                );
                $cxContext = stream_context_create($aContext);
            try{
                
                $get = @file_get_contents("http://api.bing.net/json.aspx?AppId=E6FF55E71CD243D4C518730C491DEB1837CC0FD2&Query=".urlencode($keyword) ."&Sources=Web&Web.count=20", False, $cxContext);
                if(!$get) return  array( "No Internet Connection..."  );



                 $decode = json_decode($get, TRUE); // TRUE for in array format
                 //$data=  array( 'decode' => $decode) ;

                 return $decode ;

                 }
            catch (Exception $e)
                 {
                    return "No Internet Connection..." ;
                 }
     }

     
     function searchPublicSituationPublicSearch($keyword)
     {

     
         $q2 = "select * from situation where privacyType = 'public' and name in  ( $keyword )  " ;

         // echo $q2 ;
          $data='';
          $table = $this->db->query($q2);

         // echo "here" ;
          //print_r($table)  

          foreach ($table->result() as $row)
          {

              $data[] = $row ;  
          }


          return $data  ; 
     }

     
     function searchPublicSituation($keyword)
     {

     
         $q2 = "select * from situation where privacyType = 'public' and name in  ( $keyword )  " ;
        
          $data='';
          $table = $this->db->query($q2);

         // echo "here" ;
          //print_r($table)  

          foreach ($table->result() as $row)
          {

              $data[] = $row ;  
          }


          return $data  ; 
     }
}


?>
